
import React from "react";
import axios from "axios";

export default function ExportCard({ api }) {
  const download = async () => {
    const { data } = await axios.get(`${api}/export`, { responseType: "blob" });
    const url = window.URL.createObjectURL(new Blob([data]));
    const link = document.createElement("a");
    link.href = url;
    link.setAttribute("download", "ff5_template.csv");
    document.body.appendChild(link);
    link.click();
    link.remove();
  };

  return (
    <div className="bg-white rounded-xl shadow p-6">
      <h2 className="text-lg font-semibold mb-4">4. 导出报告</h2>
      <p className="text-sm text-gray-600 mb-4">下载示例模板或分析结果</p>
      <button
        onClick={download}
        className="w-full bg-gray-800 text-white py-2 rounded hover:bg-gray-900"
      >
        下载 CSV 模板
      </button>
    </div>
  );
}
